import { getPartnerTop, getCount, getPartnerCount } from '@/api/partner'
export default {
  namespaced: true,
  state () {
    return {
      partnersTop: [],
      count: '',
      partnersCount: ''
    }
  },
  mutations: {
    setPartner (state, payload) {
      const res = payload.reduce((prev, item) => {
        return prev + item.value
      }, 0)
      console.log(res)
      payload.forEach(item => {
        item.value = item.value / res
        item.name = item.name + `(${item.value * 100 + '%'})`
      })
      console.log(payload)

      state.partnersTop = payload
    },
    setCount (state, payload) {
      state.count = payload
    },
    setPartnerCount (state, payload) {
      state.partnersCount = payload
    }
  },
  actions: {
    async getpartner (context) {
      const res = await getPartnerTop()
      context.commit('setPartner', res)
    },

    async getCount (context) {
      const res = await getCount()
      context.commit('setCount', res)
    },
    async getPartnerCount (context) {
      const res = await getPartnerCount()
      context.commit('setPartnerCount', res)
    }
  }
}
